package club.gskj.system.controller;


import club.gskj.handler.BusinessException;
import club.gskj.response.Result;
import club.gskj.response.ResultCode;
import club.gskj.system.entity.Department;
import club.gskj.system.service.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 康纳~
 * @since 2020-11-21
 */
// 部门 控制器
@Api(value = "部门模块", tags = "部门管理接口")
@RestController
@RequestMapping("/department")
@CrossOrigin
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/findDeptsAndCount")
    @ApiOperation(value = "查询部门列表", notes = "查询所有该部门下对应的人数")
    public Result findDeptAndCount() {
        List<Department> depts = departmentService.findDeptAndCount();
        if (depts == null || depts.size() <= 0) {
            throw new BusinessException(ResultCode.DEPARTMENT_NOT_EXIST.getCode(), ResultCode.DEPARTMENT_NOT_EXIST.getMessgae());
        }
        return Result.ok().data("deps", depts);
    }
}

